﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DALFactory;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class CommonMethodBLL
    {
        private static readonly IAppSettingDA appSettingDA = DataAccess.CreateAppSettingDA();
        private static readonly IBillingEntityDA billingentityDA = DataAccess.CreateBillingEntityDA();
        private static readonly ICarrierDA carrierDA = DataAccess.CreateCarrierDA();
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private static readonly IContractDA contractDA = DataAccess.CreateContractDA();
        private static readonly ICustomerDA customerDA = DataAccess.CreateCustomerDA();
        private List<string> dataBaseID;
        private static readonly IExportDeclarationsDA exportDeclarationsDA = DataAccess.CreateExportDeclarationsDA();
        private static readonly IGlobalSettingDA globalSettingDA = DataAccess.CreateGlobalSettingDA();
        private static readonly IImportDeclarationsDA importDeclarationsDA = DataAccess.CreateImportDeclarationsDA();
        private static readonly IOrdersDA ordersDA = DataAccess.CreateOrdersDA();
        private static readonly IOwnerDA ownerDA = DataAccess.CreateOwnerDA();
        private static readonly IPrintControlDA printControlDA = DataAccess.CreatePrintControlDA();
        private PubParasInfo pubParasInfo;
        private static readonly IReceiptDA receiptDA = DataAccess.CreateReceiptDA();
        private static readonly IUserBillingentityDA userbillingentityDA = DataAccess.CreateUserBillingentityDA();
        private static readonly IUserCarrierDA usercarrierDA = DataAccess.CreateUserCarrierDA();
        private static readonly IUserCustomerDA usercustomerDA = DataAccess.CreateUserCustomerDA();
        private static readonly IUserOwnerDA userownerDA = DataAccess.CreateUserOwnerDA();
        private static readonly IUserVendorDA uservendorDA = DataAccess.CreateUserVendorDA();
        private static readonly IVendorDA vendorDA = DataAccess.CreateVendorDA();

        public CommonMethodBLL()
        {
            this.pubParasInfo = null;
        }

        public CommonMethodBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public CommonMethodBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string AuditContractByContractID(List<string> contractID, string audit)
        {
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string strContractID = string.Empty;
            try
            {
                for (int i = 0; contractID.Count > i; i++)
                {
                    if (contractDA.AuditContractByContractID(dataBase, tran, contractID[i], audit, whLoginID, this.pubParasInfo) > 0)
                    {
                        strContractID = strContractID + contractID[i];
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return strContractID;
        }

        public string CreatedLocation(CreatedLocationinfo createLocation, LocationInfo Location)
        {
            string LocValue = string.Empty;
            List<string> totalLocs = new List<string>();
            totalLocs = this.GetTotalLocatinIDs(createLocation);
            ILocationDA locationDA = DataAccess.CreateLocationDA();
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < totalLocs.Count; i++)
                {
                    LocationInfo locationEntity = new LocationInfo {
                        Abc = Location.Abc,
                        CheckDig = Location.CheckDig,
                        CreatedBy = Location.CreatedBy,
                        CreatedDate = Location.CreatedDate,
                        Cube = Location.Cube,
                        CubicCapacity = Location.CubicCapacity,
                        FootPrint = Location.FootPrint,
                        Height = Location.Height,
                        IsActive = Location.IsActive,
                        IsLoseID = Location.IsLoseID,
                        IsMultiLot = Location.IsMultiLot,
                        IsMultiSku = Location.IsMultiSku,
                        Length = Location.Length,
                        LocCategory = Location.LocCategory,
                        LocFlag = Location.LocFlag,
                        LocHandling = Location.LocHandling,
                        LocLevel = Location.LocLevel,
                        LocTemplateID = Location.LocTemplateID,
                        LocUsage = Location.LocUsage,
                        LogicalLoc = Location.LogicalLoc,
                        StackLimit = Location.StackLimit,
                        Status = Location.Status,
                        SystemCreated = Location.SystemCreated,
                        UpdatedBy = Location.CreatedBy,
                        UpdatedDate = DateTime.Now,
                        WeightCapacity = Location.WeightCapacity,
                        Width = Location.Width,
                        XCoord = Location.XCoord,
                        YCoord = Location.YCoord,
                        ZCoord = Location.ZCoord,
                        ZoneID = Location.ZoneID,
                        Loc = totalLocs[i]
                    };
                    if (locationDA.CheckLocationIDUnique(dataBase, tran, locationEntity.Loc, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2330_001", this.pubParasInfo.UserLanguage, new List<string> { locationEntity.Loc });
                    }
                    locationDA.InsertLocation(dataBase, tran, locationEntity, this.dataBaseID[0]);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                LocValue = ex.Message;
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return LocValue;
        }

        public string DeleteCustGridviewInfos(string functionID, string gridviewID)
        {
            if (DataAccess.CreateCustGridviewDA().DeleteCustGridview(functionID, gridviewID, this.dataBaseID[0], this.pubParasInfo) > 0)
            {
                return (functionID + "," + gridviewID);
            }
            return "";
        }

        private int ExchangeLetter2Num(string letter)
        {
            switch (letter.ToUpper())
            {
                case "A":
                    return 1;

                case "B":
                    return 2;

                case "C":
                    return 3;

                case "D":
                    return 4;

                case "E":
                    return 5;

                case "F":
                    return 6;

                case "G":
                    return 7;

                case "H":
                    return 8;

                case "I":
                    return 9;

                case "J":
                    return 10;

                case "K":
                    return 11;

                case "L":
                    return 12;

                case "M":
                    return 13;

                case "N":
                    return 14;

                case "O":
                    return 15;

                case "P":
                    return 0x10;

                case "Q":
                    return 0x11;

                case "R":
                    return 0x12;

                case "S":
                    return 0x13;

                case "T":
                    return 20;

                case "U":
                    return 0x15;

                case "V":
                    return 0x16;

                case "W":
                    return 0x17;

                case "X":
                    return 0x18;

                case "Y":
                    return 0x19;

                case "Z":
                    return 0x1a;

                case "0":
                    return 0x1b;

                case "1":
                    return 0x1c;

                case "2":
                    return 0x1d;

                case "3":
                    return 30;

                case "4":
                    return 0x1f;

                case "5":
                    return 0x20;

                case "6":
                    return 0x21;

                case "7":
                    return 0x22;

                case "8":
                    return 0x23;

                case "9":
                    return 0x24;
            }
            return 0;
        }

        private string ExchangeNum2Letter(int num)
        {
            string letter = string.Empty;
            switch (num.ToString())
            {
                case "1":
                    return "A";

                case "2":
                    return "B";

                case "3":
                    return "C";

                case "4":
                    return "D";

                case "5":
                    return "E";

                case "6":
                    return "F";

                case "7":
                    return "G";

                case "8":
                    return "H";

                case "9":
                    return "I";

                case "10":
                    return "J";

                case "11":
                    return "K";

                case "12":
                    return "L";

                case "13":
                    return "M";

                case "14":
                    return "N";

                case "15":
                    return "O";

                case "16":
                    return "P";

                case "17":
                    return "Q";

                case "18":
                    return "R";

                case "19":
                    return "S";

                case "20":
                    return "T";

                case "21":
                    return "U";

                case "22":
                    return "V";

                case "23":
                    return "W";

                case "24":
                    return "X";

                case "25":
                    return "Y";

                case "26":
                    return "Z";

                case "27":
                    return "0";

                case "28":
                    return "1";

                case "29":
                    return "2";

                case "30":
                    return "3";

                case "31":
                    return "4";

                case "32":
                    return "5";

                case "33":
                    return "6";

                case "34":
                    return "7";

                case "35":
                    return "8";

                case "36":
                    return "9";
            }
            return letter;
        }

        private string FormatStrLength(string str, int length)
        {
            if (str.Length < length)
            {
                int balance = length - str.Length;
                for (int i = 0; i < balance; i++)
                {
                    str = "0" + str;
                }
            }
            return str;
        }

        public List<AppSettingInfo> GetAllAppSettingInfo()
        {
            return appSettingDA.GetAllAppSetting();
        }

        public List<VisualLocationInfo> GetAllVisualLocationInfo(VisualLocationQueryEntity VisualLocQuery)
        {
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(VisualLocQuery.Loc))
            {
                sqlWhere.Add(" L.Loc ='" + VisualLocQuery.Loc + "'");
            }
            if (!string.IsNullOrEmpty(VisualLocQuery.Lot))
            {
                sqlWhere.Add(" LLL.Lot ='" + VisualLocQuery.Lot + "'");
            }
            if (!string.IsNullOrEmpty(VisualLocQuery.Lpn))
            {
                sqlWhere.Add(" LLL.LPN_ID ='" + VisualLocQuery.Lpn + "'");
            }
            if (!string.IsNullOrEmpty(VisualLocQuery.OwnerID))
            {
                sqlWhere.Add(" ISL.Owner_ID ='" + VisualLocQuery.OwnerID + "'");
            }
            if (!string.IsNullOrEmpty(VisualLocQuery.SkuID))
            {
                sqlWhere.Add(" ISL.SKU_ID ='" + VisualLocQuery.SkuID + "'");
            }
            if (!string.IsNullOrEmpty(VisualLocQuery.Status))
            {
                sqlWhere.Add(" L.STATUS ='" + VisualLocQuery.Status + "'");
            }
            if (!string.IsNullOrEmpty(VisualLocQuery.ZoneID))
            {
                sqlWhere.Add(" L.ZONE_ID ='" + VisualLocQuery.ZoneID + "'");
            }
            string currentWHName = this.dataBaseID[0];
            return commonMethod.GetAllVisualLocationInfo(sqlWhere, currentWHName);
        }

        public LotTemplateInfo GetAttributeInfoBySkuID(string SkuID, string OwnerID)
        {
            return commonMethod.GetAttributeInfoBySkuID(SkuID, OwnerID, this.dataBaseID[0]);
        }

        public DataSet GetAuthorizationUserByType(string Type, string entityID)
        {
            DataSet userDS = null;
            string CS40001 = Type;
            if (CS40001 == null)
            {
                return userDS;
            }
            if (!(CS40001 == "OWNER"))
            {
                if (CS40001 != "CUSTOMER")
                {
                    if (CS40001 == "VENDOR")
                    {
                        return uservendorDA.GetAuthorizationUserByVendorID(entityID, this.dataBaseID[0]);
                    }
                    if (CS40001 == "CARRIER")
                    {
                        return usercarrierDA.GetAuthorizationUserByCarrierID(entityID, this.dataBaseID[0]);
                    }
                    if (CS40001 != "BILLING_ENTITY")
                    {
                        return userDS;
                    }
                    return userbillingentityDA.GetAuthorizationUserByBillingentityID(entityID, this.dataBaseID[0]);
                }
            }
            else
            {
                return userownerDA.GetAuthorizationUserByOwnerID(entityID, this.dataBaseID[0]);
            }
            return usercustomerDA.GetAuthorizationUserByCustomerID(entityID, this.dataBaseID[0]);
        }

        public List<OwnerInfo> GetAuthorizedOwnerByUserID(string userID)
        {
            return DataAccess.CreateUserOwnerDA().GetAuthorizedOwnerByUserID(userID, this.dataBaseID[0]);
        }

        public decimal GetAvailableQty(string ownerID, string skuID)
        {
            return commonMethod.GetAvailableQty(ownerID, skuID, this.dataBaseID[0]);
        }

        public List<SysCode4DDL> GetBaseInfoForDDLSource(string sourceFrom)
        {
            return commonMethod.GetBaseInfoForDDLSource(sourceFrom, this.dataBaseID[0]);
        }

        public List<CartonGroup4DDL> GetCartonGroup4Select()
        {
            return commonMethod.GetCartonGroup4Select(this.dataBaseID[0]);
        }

        public List<CustGridviewInfo> GetCustGridviewInfos(string functionID, string gridviewID)
        {
            return DataAccess.CreateCustGridviewDA().GetCustGridviewInfos(functionID, gridviewID, this.dataBaseID[0], this.pubParasInfo);
        }

        public List<CycleCountRule4DDL> GetCycleCountRule4Select()
        {
            return commonMethod.GetCycleCountRule4Select(this.dataBaseID[0]);
        }

        private List<string> GetEveryFieldLocString(string begin, string end, int length, string type)
        {
            List<string> fieldLoc = new List<string>();
            type = (type.ToUpper() == "ALPHA") ? "C" : "N";
            string CS40001 = type;
            if (CS40001 == null)
            {
                return fieldLoc;
            }
            if (!(CS40001 == "N"))
            {
                if (CS40001 != "C")
                {
                    return fieldLoc;
                }
            }
            else
            {
                return this.GetLocStringField(int.Parse(begin), int.Parse(end), length);
            }
            return this.GetLocStringField4Char(begin, end, length);
        }

        public List<FieldNameInfo> GetFieldNameByTableName(string TableName)
        {
            return commonMethod.GetFieldNameByTableName(TableName, this.dataBaseID[0]);
        }

        public DataSet GetInitGridViewInfoByQueryEntity(InitGridviewQueryEntity initGridviewQuery)
        {
            DataSet ds = null;
            if (initGridviewQuery == null)
            {
                return ds;
            }
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(initGridviewQuery.FunctionID))
            {
                sqlWhere.Add(" FL.MENU_STRING " + initGridviewQuery.FunctionID);
            }
            if (!string.IsNullOrEmpty(initGridviewQuery.GridviewID))
            {
                sqlWhere.Add(" IG.GRIDVIEW_ID " + initGridviewQuery.GridviewID);
            }
            if (!string.IsNullOrEmpty(initGridviewQuery.FunctionName))
            {
                sqlWhere.Add(" T.[TEXT] " + initGridviewQuery.FunctionName);
            }
            if (!string.IsNullOrEmpty(initGridviewQuery.FunctionGroupName))
            {
                sqlWhere.Add(" T2.[TEXT] " + initGridviewQuery.FunctionGroupName);
            }
            return DataAccess.CreateInitGridviewDA().GetInitGridViewInfoByQueryEntity(sqlWhere, initGridviewQuery, this.dataBaseID[0]);
        }

        public List<InitGridviewInfo> GetInitGridviewInfos(string functionID, string gridviewID)
        {
            return DataAccess.CreateInitGridviewDA().GetInitGridviewByID(functionID, gridviewID, this.dataBaseID[0]);
        }

        public DataSet GetInvSkuQtyByOwnerID(string ownerID)
        {
            return commonMethod.GetInvSkuQtyByOwnerID(ownerID, this.dataBaseID[0]);
        }

        private List<string> GetLocStringField(List<int> Field1)
        {
            List<string> locField = new List<string>();
            for (int i = 0; i < Field1.Count; i++)
            {
                locField.Add(this.ExchangeNum2Letter(Field1[i]));
            }
            return locField;
        }

        private List<string> GetLocStringField(List<int> Field1, List<int> Field2)
        {
            List<string> locField = new List<string>();
            for (int i = 0; i < Field1.Count; i++)
            {
                for (int j = 0; j < Field2.Count; j++)
                {
                    locField.Add(this.ExchangeNum2Letter(Field1[i]) + this.ExchangeNum2Letter(Field2[j]));
                }
            }
            return locField;
        }

        private List<string> GetLocStringField(List<int> Field1, List<int> Field2, List<int> Field3)
        {
            List<string> locField = new List<string>();
            for (int i = 0; i < Field1.Count; i++)
            {
                for (int j = 0; j < Field2.Count; j++)
                {
                    for (int k = 0; k < Field3.Count; k++)
                    {
                        locField.Add(this.ExchangeNum2Letter(Field1[i]) + this.ExchangeNum2Letter(Field2[j]) + this.ExchangeNum2Letter(Field3[k]));
                    }
                }
            }
            return locField;
        }

        private List<string> GetLocStringField(int beginNum, int endNum, int length)
        {
            List<string> locField = new List<string>();
            for (int i = beginNum; i < (endNum + 1); i++)
            {
                locField.Add(this.FormatStrLength(i.ToString(), length));
            }
            return locField;
        }

        private List<string> GetLocStringField(List<int> Field1, List<int> Field2, List<int> Field3, List<int> Field4)
        {
            List<string> locField = new List<string>();
            for (int i = 0; i < Field1.Count; i++)
            {
                for (int j = 0; j < Field2.Count; j++)
                {
                    for (int k = 0; k < Field3.Count; k++)
                    {
                        for (int l = 0; l < Field4.Count; l++)
                        {
                            locField.Add(this.ExchangeNum2Letter(Field1[i]) + this.ExchangeNum2Letter(Field2[j]) + this.ExchangeNum2Letter(Field3[k]) + this.ExchangeNum2Letter(Field4[l]));
                        }
                    }
                }
            }
            return locField;
        }

        private List<string> GetLocStringField(List<int> Field1, List<int> Field2, List<int> Field3, List<int> Field4, List<int> Field5)
        {
            List<string> locField = new List<string>();
            for (int i = 0; i < Field1.Count; i++)
            {
                for (int j = 0; j < Field2.Count; j++)
                {
                    for (int k = 0; k < Field3.Count; k++)
                    {
                        for (int m = 0; m < Field4.Count; m++)
                        {
                            for (int n = 0; n < Field4.Count; n++)
                            {
                                locField.Add(this.ExchangeNum2Letter(Field1[i]) + this.ExchangeNum2Letter(Field2[j]) + this.ExchangeNum2Letter(Field3[k]) + this.ExchangeNum2Letter(Field4[m]) + this.ExchangeNum2Letter(Field4[n]));
                            }
                        }
                    }
                }
            }
            return locField;
        }

        private List<string> GetLocStringField4Char(string begin, string end, int length)
        {
            int i;
            char[] tempbeginChar = begin.ToCharArray();
            char[] tempendChar = end.ToCharArray();
            List<char> beginChar = new List<char>();
            List<char> endChar = new List<char>();
            for (i = 0; i < tempbeginChar.Length; i++)
            {
                beginChar.Add(tempbeginChar[i]);
                endChar.Add(tempendChar[i]);
            }
            List<List<int>> fieldList = new List<List<int>>();
            for (i = 0; i < length; i++)
            {
                char CS00002 = beginChar[i];
                int beginInt = this.ExchangeLetter2Num(CS00002.ToString());
                int endInt = this.ExchangeLetter2Num(endChar[i].ToString());
                List<int> field = new List<int>();
                for (int j = beginInt; j < (endInt + 1); j++)
                {
                    field.Add(j);
                }
                fieldList.Add(field);
            }
            List<string> locField = new List<string>();
            switch (length)
            {
                case 1:
                    return this.GetLocStringField(fieldList[0]);

                case 2:
                    return this.GetLocStringField(fieldList[0], fieldList[1]);

                case 3:
                    return this.GetLocStringField(fieldList[0], fieldList[1], fieldList[2]);

                case 4:
                    return this.GetLocStringField(fieldList[0], fieldList[1], fieldList[2], fieldList[3]);

                case 5:
                    return this.GetLocStringField(fieldList[0], fieldList[1], fieldList[2], fieldList[3], fieldList[4]);
            }
            return locField;
        }

        public List<LotAttributeCodeInfo> GetLotAttributCodeByGroupID(string groupID)
        {
            return commonMethod.GetLotAttributCodeByGroupID(groupID, this.dataBaseID[0]);
        }

        public List<string> GetLotAttributeCode4LotTemplate()
        {
            return commonMethod.GetLotAttributeCode4LotTemplate(this.dataBaseID[0]);
        }

        public List<LotTemplate4DDL> GetLotTemplate4Select()
        {
            return commonMethod.GetLotTemplate4Select(this.dataBaseID[0]);
        }

        public List<string> GetOrderIDLineIDByPickDetailID(List<string> PickDetailID)
        {
            return commonMethod.GetOrderIDLineIDByPickDetailID(PickDetailID, this.dataBaseID[0]);
        }

        public List<PreferenceValueInfo> GetPreferenceValueByID(string preferenceID)
        {
            return commonMethod.GetPreferenceValueByID(preferenceID);
        }

        public List<ReceiptValidation4DDL> GetReceiptValidation4Select()
        {
            return commonMethod.GetReceiptValidation4Select(this.dataBaseID[0]);
        }

        public DataSet GetRelatedOrders(string Type, string skuID, string ownerID, string lot, string loc, string lpn)
        {
            return commonMethod.GetRelatedOrders(Type, skuID, ownerID, lot, loc, lpn, this.dataBaseID[0]);
        }

        public List<Rule4DDL> GetRules4Select(string ruleID)
        {
            return commonMethod.GetRules4Select(ruleID, this.dataBaseID[0]);
        }

        public DataSet GetShowGridviewInfo(string functionID, string gridviewID)
        {
            return commonMethod.GetShowGridviewInfo(functionID, gridviewID, this.dataBaseID[0], this.pubParasInfo);
        }

        public SkuInfo GetSkuByBarcode(string barcode)
        {
            return DataAccess.CreateSkuDA().GetSkuByBarcode(barcode, this.dataBaseID[0], this.pubParasInfo);
        }

        public SkuInfo GetSkuInfoByUserOwner(string skuID, string userID)
        {
            return commonMethod.GetSkuInfoByUserOwner(skuID, userID, this.dataBaseID[0], this.pubParasInfo);
        }

        public List<SkuInfo> GetSkuInfosByOwnerIDAndBarCode(string ownerID, string barCode)
        {
            return DataAccess.CreateSkuDA().GetSkuInfosByOwnerIDAndBarCode(ownerID, barCode, this.dataBaseID[0], this.pubParasInfo);
        }

        public List<SysCode4DDL> GetSysCode4DDL()
        {
            return commonMethod.GetSysCode4DDL(this.pubParasInfo.UserLanguage, this.dataBaseID[0]);
        }

        public List<SysCode4DDL> GetSysCodeForDropDownList(string sysCodeType, string language)
        {
            return commonMethod.GetSysCodeForDropDownList(sysCodeType, language, this.dataBaseID[0]);
        }

        private List<string> GetTotalLocatinIDs(CreatedLocationinfo createLocation)
        {
            List<string> locs1;
            int i;
            List<string> locs2;
            int j;
            List<string> locs3;
            int k;
            List<string> locs4;
            int m;
            List<string> totalLocs = new List<string>();
            string split = createLocation.SeperatorChar;
            if (createLocation.LocationLength == 1)
            {
                locs1 = new List<string>();
                locs1 = this.GetEveryFieldLocString(createLocation.Field1BeginStr.ToUpper(), createLocation.Field1EndStr.ToUpper(), createLocation.Field1Length, createLocation.Field1Type.ToUpper());
                for (i = 0; i < locs1.Count; i++)
                {
                    totalLocs.Add(locs1[i]);
                }
                return totalLocs;
            }
            if (createLocation.LocationLength == 2)
            {
                locs1 = new List<string>();
                locs2 = new List<string>();
                locs1 = this.GetEveryFieldLocString(createLocation.Field1BeginStr.ToUpper(), createLocation.Field1EndStr.ToUpper(), createLocation.Field1Length, createLocation.Field1Type.ToUpper());
                locs2 = this.GetEveryFieldLocString(createLocation.Field2BeginStr.ToUpper(), createLocation.Field2EndStr.ToUpper(), createLocation.Field2Length, createLocation.Field2Type.ToUpper());
                for (i = 0; i < locs1.Count; i++)
                {
                    j = 0;
                    while (j < locs2.Count)
                    {
                        totalLocs.Add(locs1[i] + split + locs2[j]);
                        j++;
                    }
                }
                return totalLocs;
            }
            if (createLocation.LocationLength == 3)
            {
                locs1 = new List<string>();
                locs2 = new List<string>();
                locs3 = new List<string>();
                locs1 = this.GetEveryFieldLocString(createLocation.Field1BeginStr.ToUpper(), createLocation.Field1EndStr.ToUpper(), createLocation.Field1Length, createLocation.Field1Type.ToUpper());
                locs2 = this.GetEveryFieldLocString(createLocation.Field2BeginStr.ToUpper(), createLocation.Field2EndStr.ToUpper(), createLocation.Field2Length, createLocation.Field2Type.ToUpper());
                locs3 = this.GetEveryFieldLocString(createLocation.Field3BeginStr.ToUpper(), createLocation.Field3EndStr.ToUpper(), createLocation.Field3Length, createLocation.Field3Type.ToUpper());
                for (i = 0; i < locs1.Count; i++)
                {
                    j = 0;
                    while (j < locs2.Count)
                    {
                        k = 0;
                        while (k < locs3.Count)
                        {
                            totalLocs.Add(locs1[i] + split + locs2[j] + split + locs3[k]);
                            k++;
                        }
                        j++;
                    }
                }
                return totalLocs;
            }
            if (createLocation.LocationLength == 4)
            {
                locs1 = new List<string>();
                locs2 = new List<string>();
                locs3 = new List<string>();
                locs4 = new List<string>();
                locs1 = this.GetEveryFieldLocString(createLocation.Field1BeginStr.ToUpper(), createLocation.Field1EndStr.ToUpper(), createLocation.Field1Length, createLocation.Field1Type.ToUpper());
                locs2 = this.GetEveryFieldLocString(createLocation.Field2BeginStr.ToUpper(), createLocation.Field2EndStr.ToUpper(), createLocation.Field2Length, createLocation.Field2Type.ToUpper());
                locs3 = this.GetEveryFieldLocString(createLocation.Field3BeginStr.ToUpper(), createLocation.Field3EndStr.ToUpper(), createLocation.Field3Length, createLocation.Field3Type.ToUpper());
                locs4 = this.GetEveryFieldLocString(createLocation.Field4BeginStr.ToUpper(), createLocation.Field4EndStr.ToUpper(), createLocation.Field4Length, createLocation.Field4Type.ToUpper());
                for (i = 0; i < locs1.Count; i++)
                {
                    j = 0;
                    while (j < locs2.Count)
                    {
                        k = 0;
                        while (k < locs3.Count)
                        {
                            m = 0;
                            while (m < locs4.Count)
                            {
                                totalLocs.Add(locs1[i] + split + locs2[j] + split + locs3[k] + split + locs4[m]);
                                m++;
                            }
                            k++;
                        }
                        j++;
                    }
                }
                return totalLocs;
            }
            if (createLocation.LocationLength == 5)
            {
                locs1 = new List<string>();
                locs2 = new List<string>();
                locs3 = new List<string>();
                locs4 = new List<string>();
                List<string> locs5 = new List<string>();
                locs1 = this.GetEveryFieldLocString(createLocation.Field1BeginStr.ToUpper(), createLocation.Field1EndStr.ToUpper(), createLocation.Field1Length, createLocation.Field1Type.ToUpper());
                locs2 = this.GetEveryFieldLocString(createLocation.Field2BeginStr.ToUpper(), createLocation.Field2EndStr.ToUpper(), createLocation.Field2Length, createLocation.Field2Type.ToUpper());
                locs3 = this.GetEveryFieldLocString(createLocation.Field3BeginStr.ToUpper(), createLocation.Field3EndStr.ToUpper(), createLocation.Field3Length, createLocation.Field3Type.ToUpper());
                locs4 = this.GetEveryFieldLocString(createLocation.Field4BeginStr.ToUpper(), createLocation.Field4EndStr.ToUpper(), createLocation.Field4Length, createLocation.Field4Type.ToUpper());
                locs5 = this.GetEveryFieldLocString(createLocation.Field5BeginStr.ToUpper(), createLocation.Field5EndStr.ToUpper(), createLocation.Field5Length, createLocation.Field5Type.ToUpper());
                for (i = 0; i < locs1.Count; i++)
                {
                    for (j = 0; j < locs2.Count; j++)
                    {
                        for (k = 0; k < locs3.Count; k++)
                        {
                            for (m = 0; m < locs4.Count; m++)
                            {
                                for (int n = 0; n < locs5.Count; n++)
                                {
                                    totalLocs.Add(locs1[i] + split + locs2[j] + split + locs3[k] + split + locs4[m] + split + locs5[n]);
                                }
                            }
                        }
                    }
                }
            }
            return totalLocs;
        }

        public List<UomList> GetUomListByPackID(string packID)
        {
            return commonMethod.GetUomListByPackID(packID, this.dataBaseID[0]);
        }

        public List<Owner4DDL> GetUserPermissionOwner(string userID)
        {
            return commonMethod.GetUserPermissionOwner(userID);
        }

        public List<WareHouseName4DDL> GetUserPermissionWareHouse(string userID)
        {
            return commonMethod.GetUserPermissionWareHouse(userID);
        }

        public List<WareHouseName4DDL> GetWareHouseName4Select()
        {
            return commonMethod.GetWareHouse4Select();
        }

        public string ImportByData(string[][] ImportByData, string dataName, string IsUpdate, PubParasInfo pubParasInfo)
        {
            switch (dataName.ToUpper())
            {
                case "CUSTOMER":
                {
                    CustomerBLL customer = new CustomerBLL(pubParasInfo);
                    return customer.CustomerImportByData(ImportByData, IsUpdate);
                }
                case "CARRIER":
                {
                    CarrierBLL carrier = new CarrierBLL(pubParasInfo);
                    return carrier.CarrierImportByData(ImportByData, IsUpdate);
                }
                case "BILLINGENTITY":
                {
                    BillingEntityBLL billingEntity = new BillingEntityBLL(pubParasInfo);
                    return billingEntity.BillingImportByData(ImportByData, IsUpdate);
                }
                case "VENDOR":
                {
                    VendorBLL vendor = new VendorBLL(pubParasInfo);
                    return vendor.VendorImportByData(ImportByData, IsUpdate);
                }
                case "SKU":
                {
                    SkuBLL sku = new SkuBLL(pubParasInfo);
                    return sku.SkuImportByData(ImportByData, IsUpdate);
                }
                case "LOCATION":
                {
                    LocationBLL location = new LocationBLL(pubParasInfo);
                    return location.LocImportByData(ImportByData, IsUpdate);
                }
                case "RECEIPTDETAIL":
                {
                    ReceiptDetailBLL receiptDetail = new ReceiptDetailBLL(pubParasInfo);
                    return receiptDetail.AsnDetailImportByData(ImportByData);
                }
                case "SHIPPINGORDERDETAIL":
                {
                    OrderDetailBLL orderDetail = new OrderDetailBLL(pubParasInfo);
                    return orderDetail.ShippingOrderDetailImportByData(ImportByData);
                }
                case "OWNER":
                {
                    TradePartnerBLL TradePartnerBLL = new TradePartnerBLL(pubParasInfo);
                    return TradePartnerBLL.OwnerImportByData(ImportByData, IsUpdate);
                }
                case "ALTERNATESKU":
                {
                    AlternateSkuBLL AlternateSkuBLL = new AlternateSkuBLL(pubParasInfo);
                    return AlternateSkuBLL.AlternateSkuImportByData(ImportByData, IsUpdate);
                }
                case "PURCHASEORDERDETAIL":
                {
                    PurchaseOrderDetailBLL purchaseOrderDetailBll = new PurchaseOrderDetailBLL(pubParasInfo);
                    return purchaseOrderDetailBll.purchaseOrderDetailImportByData(ImportByData);
                }
                case "MOVEMENTDETAIL":
                {
                    MovementDetailBLL movementDetailBLL = new MovementDetailBLL(pubParasInfo);
                    return movementDetailBLL.MovementDetailImportByData(ImportByData);
                }
                case "DISTRIBUTIONRANGE":
                {
                    DistributionRangeBLL distributionRangeBLL = new DistributionRangeBLL(pubParasInfo);
                    return distributionRangeBLL.DistributionRangeImportByData(ImportByData);
                }
                case "ORDERTRACKING":
                {
                    OrdersBLL ordersBLL = new OrdersBLL(pubParasInfo);
                    return ordersBLL.OrderTrackingImportByData(ImportByData);
                }
                case "SHIPPINGCONTAINERDETAIL":
                {
                    ShipmentContainerBLL shipmentContainerBLL = new ShipmentContainerBLL(pubParasInfo);
                    return shipmentContainerBLL.ShippingContainerDetailImportByData(ImportByData);
                }
                case "LPN":
                {
                    LpnBLL lpnBLL = new LpnBLL(pubParasInfo);
                    return lpnBLL.LPNImportByData(ImportByData);
                }
            }
            return "未找到合适的数据导入地址!";
        }

        public string ImportByDataSet(DataSet ds, string dataName, PubParasInfo pubParasInfo)
        {
            switch (dataName.ToUpper())
            {
                case "SHIPPINGORDER":
                {
                    OrdersBLL ordersBLL = new OrdersBLL(pubParasInfo);
                    return ordersBLL.ImportByDataSet(ds);
                }
                case "SALESORDERDETAIL":
                {
                    SalesOrderBLL salesOrderBLL = new SalesOrderBLL(pubParasInfo);
                    return salesOrderBLL.ImportByDataSet(ds);
                }
            }
            return "未找到合适的数据导入地址!";
        }

        public string InsertCustGridviewInfos(List<CustGridviewInfo> custGridviewInfo)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                ICustGridviewDA custGridviewDA = DataAccess.CreateCustGridviewDA();
                custGridviewDA.DeleteCustGridview(dataBase, tran, custGridviewInfo[0].FunctionID, custGridviewInfo[0].GirdviewID, this.dataBaseID[0], this.pubParasInfo);
                result = custGridviewDA.InsertCustGridview(dataBase, tran, custGridviewInfo, this.dataBaseID[0], this.pubParasInfo);
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ((result > 0) ? (custGridviewInfo[0].FunctionID + " " + custGridviewInfo[0].GirdviewID) : "");
        }

        public string LpnGenerateByGenerateType(LPNGenParams lpnGenParams)
        {
            LPNGenerate lpnGenerate = new LPNGenerate();
            string CS40001 = lpnGenParams.GenerateType.ToUpper();
            if ((CS40001 != null) && (CS40001 == "SKYTRANS"))
            {
                return lpnGenerate.SkyTransLpnGenerate(lpnGenParams, this.pubParasInfo, this.dataBaseID[0]);
            }
            return "未找到与生成类型匹配的lpn生成方法,请核对！";
        }

        public string ReleasePrintControl(List<PrintControlInfo> printControlInfos)
        {
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string result = string.Empty;
            try
            {
                foreach (PrintControlInfo printControlInfo in printControlInfos)
                {
                    if (printControlDA.CheckPrintControlIDUnique(dataBase, tran, printControlInfo.PrintType, printControlInfo.DocLineID, whLoginID))
                    {
                        PrintControlInfo tempPrintControlInfo = printControlDA.GetPrintControlByID(dataBase, tran, printControlInfo.PrintType, printControlInfo.DocLineID, whLoginID);
                        if (tempPrintControlInfo.IsPrinted != "N")
                        {
                            tempPrintControlInfo.IsPrinted = "N";
                            tempPrintControlInfo.UpdatedBy = this.pubParasInfo.UserID;
                            tempPrintControlInfo.UpdatedDate = DateTime.Now;
                            printControlDA.UpdatePrintControl(dataBase, tran, tempPrintControlInfo, whLoginID);
                            result = result + printControlInfo.DocLineID + ",";
                        }
                    }
                }
                if (!string.IsNullOrEmpty(result))
                {
                    result = result.Substring(0, result.Length - 1);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public string SavePrintControl(List<PrintControlInfo> printControlInfos)
        {
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string result = string.Empty;
            try
            {
                foreach (PrintControlInfo printControlInfo in printControlInfos)
                {
                    if (printControlDA.CheckPrintControlIDUnique(dataBase, tran, printControlInfo.PrintType, printControlInfo.DocLineID, whLoginID))
                    {
                        PrintControlInfo tempPrintControlInfo = printControlDA.GetPrintControlByID(dataBase, tran, printControlInfo.PrintType, printControlInfo.DocLineID, whLoginID);
                        if (tempPrintControlInfo.IsPrinted != "Y")
                        {
                            tempPrintControlInfo.IsPrinted = "Y";
                            tempPrintControlInfo.PrintCount++;
                            tempPrintControlInfo.UpdatedBy = this.pubParasInfo.UserID;
                            tempPrintControlInfo.UpdatedDate = DateTime.Now;
                            printControlDA.UpdatePrintControl(dataBase, tran, tempPrintControlInfo, whLoginID);
                        }
                    }
                    else
                    {
                        printControlInfo.IsPrinted = "Y";
                        printControlInfo.PrintCount = 1;
                        printControlInfo.CreatedBy = this.pubParasInfo.UserID;
                        printControlInfo.CreatedDate = DateTime.Now;
                        printControlInfo.UpdatedBy = this.pubParasInfo.UserID;
                        printControlInfo.UpdatedDate = DateTime.Now;
                        printControlDA.InsertPrintControl(dataBase, tran, printControlInfo, whLoginID);
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public DataSet SearchDataByKey(string key, string key2, string Type)
        {
            return commonMethod.SearchDataByKey(key, key2, Type, this.dataBaseID[0], this.pubParasInfo);
        }

        public string SqlAnalyse(string strSql)
        {
            return commonMethod.SqlAnalyse(strSql, this.dataBaseID[0]);
        }

        public DataSet SqlQuery(string sql, BaseQuery baseQuery)
        {
            return commonMethod.SqlQuery(sql, baseQuery);
        }

        public int UpdateASNAndSOSingleField(string orderType, string orderID, string updatedField, string value)
        {
            return commonMethod.UpdateASNAndSOSingleField(orderType, orderID, updatedField, value, this.pubParasInfo.UserID, this.dataBaseID[0]);
        }

        public int UpdateAuthorizationUserByType(string authorizationUser, string Type, string entityID)
        {
            int i;
            DataBase dataBase;
            DbConnection conn;
            DbTransaction tran;
            Exception ex;
            int result = -1;
            string defaultUser = string.Empty;
            string[] strAuthorizedUser = authorizationUser.Split(new char[] { ';' });
            if (Type == "OWNER")
            {
                if (!ownerDA.CheckTradePartnerIDUnique(entityID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_003", this.pubParasInfo.UserLanguage, new List<string> { entityID });
                }
                List<UserOwnerInfo> newuserOwnerListInfo = new List<UserOwnerInfo>();
                List<UserOwnerInfo> userOwnerListInfo = userownerDA.GetUserOwnerInfoByOwnerIDandUserID(entityID, ConstUtils.CONST_GLOBAL_TABLE);
                for (i = 0; strAuthorizedUser.Length > i; i++)
                {
                    defaultUser = "N";
                    if (userOwnerListInfo != null)
                    {
                        defaultUser = "N";
                        foreach (UserOwnerInfo userOwnerInfo in userOwnerListInfo)
                        {
                            if (strAuthorizedUser[i] == userOwnerInfo.UserID)
                            {
                                defaultUser = userOwnerInfo.IsDefault;
                                break;
                            }
                        }
                    }
                    UserOwnerInfo newuserOwnerInfo = new UserOwnerInfo {
                        UserID = strAuthorizedUser[i],
                        OwnerID = entityID,
                        IsDefault = defaultUser,
                        CreatedBy = this.pubParasInfo.UserID,
                        CreatedDate = DateTime.Now,
                        UpdatedBy = this.pubParasInfo.UserID,
                        UpdatedDate = DateTime.Now
                    };
                    newuserOwnerListInfo.Add(newuserOwnerInfo);
                }
                dataBase = new DataBase();
                conn = dataBase.connection;
                conn.Open();
                tran = conn.BeginTransaction();
                try
                {
                    userownerDA.DeleteUserOwnerByOwnerID(dataBase, tran, entityID, ConstUtils.CONST_GLOBAL_TABLE);
                    result = userownerDA.InsertUserOwnerByOwnerID(dataBase, tran, newuserOwnerListInfo, ConstUtils.CONST_GLOBAL_TABLE);
                    tran.Commit();
                }
                catch (Exception exception1)
                {
                    ex = exception1;
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            if (Type == "CUSTOMER")
            {
                if (!customerDA.CheckCustomerIDUnique(entityID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2120_003", this.pubParasInfo.UserLanguage, new List<string> { entityID });
                }
                List<UserCustomerInfo> newuserCustomerListInfo = new List<UserCustomerInfo>();
                List<UserCustomerInfo> userCustomerListInfo = usercustomerDA.GetUserCustomerInfoByCustomerIDandUserID(entityID, ConstUtils.CONST_GLOBAL_TABLE);
                for (i = 0; strAuthorizedUser.Length > i; i++)
                {
                    defaultUser = "N";
                    if (userCustomerListInfo != null)
                    {
                        defaultUser = "N";
                        foreach (UserCustomerInfo userCustomerInfo in userCustomerListInfo)
                        {
                            if (strAuthorizedUser[i] == userCustomerInfo.UserID)
                            {
                                defaultUser = userCustomerInfo.IsDefault;
                                break;
                            }
                        }
                    }
                    UserCustomerInfo newuserCustomerInfo = new UserCustomerInfo {
                        UserID = strAuthorizedUser[i],
                        CustomerID = entityID,
                        IsDefault = defaultUser,
                        CreatedBy = this.pubParasInfo.UserID,
                        CreatedDate = DateTime.Now,
                        UpdatedBy = this.pubParasInfo.UserID,
                        UpdatedDate = DateTime.Now
                    };
                    newuserCustomerListInfo.Add(newuserCustomerInfo);
                }
                dataBase = new DataBase();
                conn = dataBase.connection;
                conn.Open();
                tran = conn.BeginTransaction();
                try
                {
                    usercustomerDA.DeleteUserCustomerByCustomerID(dataBase, tran, entityID, ConstUtils.CONST_GLOBAL_TABLE);
                    result = usercustomerDA.InsertUserCustomerByCustomerID(dataBase, tran, newuserCustomerListInfo, ConstUtils.CONST_GLOBAL_TABLE);
                    tran.Commit();
                }
                catch (Exception exception2)
                {
                    ex = exception2;
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            if (Type == "VENDOR")
            {
                if (!vendorDA.CheckVendorIDUnique(entityID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2130_003", this.pubParasInfo.UserLanguage, new List<string> { entityID });
                }
                List<UserVendorInfo> newuserVendorListInfo = new List<UserVendorInfo>();
                List<UserVendorInfo> userVendorListInfo = uservendorDA.GetUserVendorInfoByVendorIDandUserID(entityID, ConstUtils.CONST_GLOBAL_TABLE);
                for (i = 0; strAuthorizedUser.Length > i; i++)
                {
                    defaultUser = "N";
                    if (userVendorListInfo != null)
                    {
                        defaultUser = "N";
                        foreach (UserVendorInfo userVendorInfo in userVendorListInfo)
                        {
                            if (strAuthorizedUser[i] == userVendorInfo.UserID)
                            {
                                defaultUser = userVendorInfo.IsDefault;
                                break;
                            }
                        }
                    }
                    UserVendorInfo newuserVendorInfo = new UserVendorInfo {
                        UserID = strAuthorizedUser[i],
                        VendorID = entityID,
                        IsDefault = defaultUser,
                        CreatedBy = this.pubParasInfo.UserID,
                        CreatedDate = DateTime.Now,
                        UpdatedBy = this.pubParasInfo.UserID,
                        UpdatedDate = DateTime.Now
                    };
                    newuserVendorListInfo.Add(newuserVendorInfo);
                }
                dataBase = new DataBase();
                conn = dataBase.connection;
                conn.Open();
                tran = conn.BeginTransaction();
                try
                {
                    uservendorDA.DeleteUserVendorByVendorID(dataBase, tran, entityID, ConstUtils.CONST_GLOBAL_TABLE);
                    result = uservendorDA.InsertUserVendorByVendorID(dataBase, tran, newuserVendorListInfo, ConstUtils.CONST_GLOBAL_TABLE);
                    tran.Commit();
                }
                catch (Exception exception3)
                {
                    ex = exception3;
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            if (Type == "CARRIER")
            {
                if (!carrierDA.CheckCarrierIDUnique(entityID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2140_003", this.pubParasInfo.UserLanguage, new List<string> { entityID });
                }
                List<UserCarrierInfo> newuserCarrierListInfo = new List<UserCarrierInfo>();
                List<UserCarrierInfo> userCarrierListInfo = usercarrierDA.GetUserCarrierInfoByCarrierIDandUserID(entityID, ConstUtils.CONST_GLOBAL_TABLE);
                for (i = 0; strAuthorizedUser.Length > i; i++)
                {
                    defaultUser = "N";
                    if (userCarrierListInfo != null)
                    {
                        defaultUser = "N";
                        foreach (UserCarrierInfo userCarrierInfo in userCarrierListInfo)
                        {
                            if (strAuthorizedUser[i] == userCarrierInfo.UserID)
                            {
                                defaultUser = userCarrierInfo.IsDefault;
                                break;
                            }
                        }
                    }
                    UserCarrierInfo newuserCarrierInfo = new UserCarrierInfo {
                        UserID = strAuthorizedUser[i],
                        CarrierID = entityID,
                        IsDefault = defaultUser,
                        CreatedBy = this.pubParasInfo.UserID,
                        CreatedDate = DateTime.Now,
                        UpdatedBy = this.pubParasInfo.UserID,
                        UpdatedDate = DateTime.Now
                    };
                    newuserCarrierListInfo.Add(newuserCarrierInfo);
                }
                dataBase = new DataBase();
                conn = dataBase.connection;
                conn.Open();
                tran = conn.BeginTransaction();
                try
                {
                    usercarrierDA.DeleteUserCarrierByCarrierID(dataBase, tran, entityID, ConstUtils.CONST_GLOBAL_TABLE);
                    result = usercarrierDA.InsertUserCarrierByCarrierID(dataBase, tran, newuserCarrierListInfo, ConstUtils.CONST_GLOBAL_TABLE);
                    tran.Commit();
                }
                catch (Exception exception4)
                {
                    ex = exception4;
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            if (Type == "BILLING_ENTITY")
            {
                if (!billingentityDA.CheckBillingEntityIDUnique(entityID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2150_003", this.pubParasInfo.UserLanguage, new List<string> { entityID });
                }
                List<UserBillingentityInfo> newuserBillingEntityListInfo = new List<UserBillingentityInfo>();
                List<UserBillingentityInfo> userBillingEntityListInfo = userbillingentityDA.GetUserBillingentityInfoByBillingentityIDandUserID(entityID, ConstUtils.CONST_GLOBAL_TABLE);
                for (i = 0; strAuthorizedUser.Length > i; i++)
                {
                    defaultUser = "N";
                    if (userBillingEntityListInfo != null)
                    {
                        defaultUser = "N";
                        foreach (UserBillingentityInfo userBillingEntityInfoInfo in userBillingEntityListInfo)
                        {
                            if (strAuthorizedUser[i] == userBillingEntityInfoInfo.UserID)
                            {
                                defaultUser = userBillingEntityInfoInfo.IsDefault;
                                break;
                            }
                        }
                    }
                    UserBillingentityInfo newuserBillingEntityInfo = new UserBillingentityInfo {
                        UserID = strAuthorizedUser[i],
                        BillingentityID = entityID,
                        IsDefault = defaultUser,
                        CreatedBy = this.pubParasInfo.UserID,
                        CreatedDate = DateTime.Now,
                        UpdatedBy = this.pubParasInfo.UserID,
                        UpdatedDate = DateTime.Now
                    };
                    newuserBillingEntityListInfo.Add(newuserBillingEntityInfo);
                }
                dataBase = new DataBase();
                conn = dataBase.connection;
                conn.Open();
                tran = conn.BeginTransaction();
                try
                {
                    userbillingentityDA.DeleteUserBillingentityByBillingentityID(dataBase, tran, entityID, ConstUtils.CONST_GLOBAL_TABLE);
                    result = userbillingentityDA.InsertUserBillingentityByBillingentityID(dataBase, tran, newuserBillingEntityListInfo, ConstUtils.CONST_GLOBAL_TABLE);
                    tran.Commit();
                }
                catch (Exception exception5)
                {
                    ex = exception5;
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            return result;
        }

        public int UpdateDeclarations(string Type, string keyID, string ExternOrderID, string CoreReleaseID, string WorkOrder)
        {
            string CS40001 = Type;
            if (CS40001 != null)
            {
                if (!(CS40001 == "RECEIPT"))
                {
                    if (CS40001 == "SHIPPING")
                    {
                        OrdersInfo ordersInfo = ordersDA.GetOrdersByID(keyID, this.dataBaseID[0], this.pubParasInfo);
                        if ((ordersInfo.ExternOrderID != ExternOrderID) && exportDeclarationsDA.CheckExportDeclarationsIDUnique(ordersInfo.ExternOrderID, this.dataBaseID[0]))
                        {
                            throw new Exception("此外部订单号:" + ordersInfo.ExternOrderID + "已报关,不能修改!");
                        }
                    }
                }
                else
                {
                    ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(keyID, this.dataBaseID[0], this.pubParasInfo);
                    if ((receiptInfo.ExternalReceiptID != ExternOrderID) && importDeclarationsDA.CheckImportDeclarationsIDUnique(receiptInfo.ExternalReceiptID, this.dataBaseID[0]))
                    {
                        throw new Exception("此外部订单号:" + receiptInfo.ExternalReceiptID + "已报关,不能修改!");
                    }
                }
            }
            return commonMethod.UpdateDeclarations(Type, keyID, ExternOrderID, CoreReleaseID, WorkOrder, this.dataBaseID[0]);
        }

        public int UpdateExternOrderID(string Type, string keyID, string ExternOrderID)
        {
            return commonMethod.UpdateExternOrderID(Type, keyID, ExternOrderID, this.dataBaseID[0]);
        }

        public string UpdateUDF(string ID, UDFInfo udfInfo, string strType)
        {
            string strID = string.Empty;
            try
            {
                if (commonMethod.UpdateUDF(ID, udfInfo, strType, this.dataBaseID[0], this.pubParasInfo) > 0)
                {
                    strID = ID;
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return strID;
        }
    }
}

